package Demo5;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

class MyThreadpool{

    BlockingQueue<Runnable> queue;

    public MyThreadpool(int n) {
queue=new ArrayBlockingQueue<>(1000);
        for (int i = 0; i <n ; i++) {
            Thread t=new Thread(()->{
                while(true){
                    try {
                       Runnable task=queue.take();
                        task.run();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            });
t.start();
        }
    }

    public void submit(Runnable task) throws InterruptedException {
        queue.put(task);
    }

}



public class Main14 {
    public static void main(String[] args) throws InterruptedException {
MyThreadpool pool=new MyThreadpool(100);
        for (int i = 0; i <1000 ; i++) {
            int id=i;
            pool.submit(()->{
                System.out.println(Thread.currentThread().getName()+" id="+id);
            });
        }

    }
}
